home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / What's New? / • What was new 03⁄99 / Tool Chest / Sample Code / Eject PC Cards Location Module / EjectPCCards code resource / EjectPCCards.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-22  |  2.0 KB  |  77 lines  |  [TEXT/CWIE]

  1. #include <NameRegistry.h>
  2. #include <PCCard.h>
  3. #include <MixedMode.h>
  4. #include <Errors.h>
  5.  
  6. #ifdef __powerc
  7. enum {
  8.     uppEjectPCCardsProcInfo = kPascalStackBased
  9.          | RESULT_SIZE (SIZE_CODE(sizeof(OSStatus)))
  10.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
  11. };
  12. ProcInfoType __procinfo = uppEjectPCCardsProcInfo;
  13. #endif
  14.  
  15. pascal OSStatus EjectPCCards (long slot);
  16.  
  17. /*
  18.     This routine will search through the name registry to find PC Card cards.  It will
  19.     then issue an eject call via PCCardEject for the requested cards.  Cards that do
  20.     not eject for some reason (usually because they are in use) are ignored and no
  21.     attempt is made to make the card un-busy and then eject it.
  22.  
  23.     slot == 0 -- eject all cards
  24.     slot == 1 -- eject lower card
  25.     slot == 2 -- eject upper card
  26. */
  27. pascal OSStatus EjectPCCards (long slot) {
  28.     OSStatus                err                = noErr;
  29.     RegEntryIter            cookie            = nil;
  30.     RegEntryID                pccardEntry;
  31.     RegEntryIterationOp        iterOp            = kRegIterDescendants;
  32.     Boolean                    done            = false;
  33.     OSType                    nodeType        = 'pccc';
  34.     long                    socketNumber    = -1;    /* a safe value */
  35.     RegPropertyValueSize    size            = sizeof (long);
  36.  
  37.     if (slot < 0 || slot > 2) {
  38.         err = paramErr;
  39.     }
  40.  
  41.     if (err == noErr) {
  42.         err = RegistryEntryIDInit (&pccardEntry);
  43.     }
  44.  
  45.     if (err == noErr) {
  46.         err = RegistryEntryIterateCreate (&cookie);
  47.     }
  48.  
  49.     if (err == noErr) {
  50.         do {
  51.             err = RegistryEntrySearch (&cookie, iterOp, &pccardEntry, &done, "PCCardNodeType", &nodeType, sizeof (OSType));
  52.  
  53.             if (!done && err == noErr) {
  54.                 /* Get the socket number so we eject only the requested slots. */
  55.                 err = RegistryPropertyGet (&pccardEntry, "SocketNumber", &socketNumber, &size);
  56.             }
  57.  
  58.             if (!done && err == noErr && ((slot - 1) == socketNumber || slot == 0)) {
  59.                 (void)PCCardEject (&pccardEntry);
  60.                 (void)RegistryEntryIDDispose (&pccardEntry);
  61.             }
  62.  
  63.             iterOp = kRegIterContinue;
  64.         } while (!done && err == noErr);
  65.     }
  66.  
  67.     (void)RegistryEntryIterateDispose (&cookie);
  68.  
  69.     return err;
  70. }
  71.  
  72. #if DEBUG
  73. void main (void) {
  74.     EjectPCCards (0);
  75. }
  76. #endif
  77.